**********************************************************************
* Paper: Voluntary Practice Tests improve Exam Performance
* Last Update: 22.02.2026
* Replication code
**********************************************************************

* load data
use "C:\Users\timba\OneDrive - Universität Bayreuth (1)\Uni\Research General\EVWL online test effectiveness assessment\Empirics\master\alldata_cleaned.dta", clear

* variable labels
label variable Total "Number Bon. Points"
label variable high_school_average "High School Grade Avg."
label variable average_grade_pre "Uni. Grade Avg. (pre)"
label variable average_grade_quant_pre "Uni. Grade Avg. Quant. (pre)"
label variable exam_semester "Exam Semester"
label variable Antritt "Exam Attempt"
label variable ECTS_passed_pre "ECTS Collected (pre)"
label variable ECTS_passed_quant_pre "Quant. ECTS Collected (pre)"
label variable ECTS_econ_of_all_pre "Share of Econ ECTS (pre)"
label variable ECTS_same_semester "ECTS Collected Same Sem."
label variable Age "Age (Years)"
label variable female "Female (=1)"
label variable Sport_konomie "Study Prog.: Sport \& Manag."
label variable Recht_Wirtschaft "Study Prog.: Law \& Econ"
label variable Rechtswissenschaft "Study Prog.: Law"
label variable Test1 "Test 1"
label variable Test2 "Test 2"
label variable Test3 "Test 3"
label variable Test4 "Test 4"


***************************************
*** Variable Definition
***************************************

* enocde variables
encode Exam, gen(Exam_fe)
encode Land_Schule, gen(Land_Schule_fe)

*** variable definition

* all covariates
global vars = "high_school_average average_grade_pre average_grade_quant_pre Antritt exam_semester ECTS_passed_pre ECTS_passed_quant_pre ECTS_econ_of_all_pre ECTS_same_semester Age female i.Exam_fe Sport_konomie Recht_Wirtschaft Rechtswissenschaft"

global vars_excluding_Recht = "high_school_average average_grade_pre average_grade_quant_pre Antritt exam_semester ECTS_passed_pre ECTS_passed_quant_pre ECTS_econ_of_all_pre ECTS_same_semester Age female i.Exam_fe Sport_konomie Recht_Wirtschaft "


***************************************
*** Trim Extreme Propensity Scores
***************************************

*** Figures 13, 14, and 15: trimming extreme propensity scores
* run this code only to obtain the robustness tests for trimmed extreme propensity scores 
/*
logit bonus_1 $vars
predict ps, pr
gen ps_ext = 0
replace ps_ext = 1 if (ps > 0.95 | ps < 0.05)

keep if ps_ext == 0
*/

*** Macro placbo testing sample 
/*
keep if macro != .
*/


***************************************
*** Table 1: Summary Stats
***************************************

*** summary statistics
* sum
estpost sum Total high_school_average average_grade_pre average_grade_quant_pre ///
	Antritt exam_semester ECTS_passed_pre ECTS_passed_quant_pre ECTS_econ_of_all_pre ECTS_same_semester ///
	Age female Sport_konomie Recht_Wirtschaft Rechtswissenschaft if !missing(points_wo_bonus, Total, high_school_average, average_grade_pre, average_grade_quant_pre, ///
    Antritt, exam_semester, ECTS_passed_pre, ECTS_passed_quant_pre, ECTS_econ_of_all_pre, ECTS_same_semester, ///
    Age, female, Sport_konomie, Recht_Wirtschaft, Rechtswissenschaft), detail
est store sum


*** export
global export = "using out.tex"
global export = ""
* esttab
esttab sum $export, ///
	cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2)) min(fmt(2)) p25(fmt(2)) p75(fmt(2)) max(fmt(2))") ///
	label ///
	noobs ///
	fragment ///
	replace	


***************************************
*** Table 2: OLS Regression
***************************************

* prepare FE
tabulate Exam_fe, generate(Exam_fe_)

* OLS (varying covariates)
eststo reg1: reg points_wo_bonus Total if !missing(points_wo_bonus, Total, high_school_average, average_grade_pre, average_grade_quant_pre, ///
    Antritt, exam_semester, ECTS_passed_pre, ECTS_passed_quant_pre, ECTS_econ_of_all_pre, ECTS_same_semester, ///
    Age, female, Sport_konomie, Recht_Wirtschaft, Rechtswissenschaft), robust
eststo reg2: reg points_wo_bonus Test1 Test2 Test3 Test4 if !missing(points_wo_bonus, Total, high_school_average, average_grade_pre, average_grade_quant_pre, ///
    Antritt, exam_semester, ECTS_passed_pre, ECTS_passed_quant_pre, ECTS_econ_of_all_pre, ECTS_same_semester, ///
    Age, female, Sport_konomie, Recht_Wirtschaft, Rechtswissenschaft), robust

eststo reg3: reg points_wo_bonus Total high_school_average average_grade_pre average_grade_quant_pre Antritt exam_semester ECTS_passed_pre ECTS_passed_quant_pre ECTS_econ_of_all_pre ECTS_same_semester Age female, robust
eststo reg4: reg points_wo_bonus Test1 Test2 Test3 Test4 high_school_average average_grade_pre average_grade_quant_pre Antritt exam_semester ECTS_passed_pre ECTS_passed_quant_pre ECTS_econ_of_all_pre ECTS_same_semester Age female, robust

eststo reg5: reg points_wo_bonus Total $vars Exam_fe_1-Exam_fe_6, robust noconstant
eststo reg6: reg points_wo_bonus Test1 Test2 Test3 Test4 $vars Exam_fe_1-Exam_fe_6, robust noconstant

*** export
global export = "using out.tex"
global export = ""

esttab reg1 reg2 reg3 reg4 reg5 reg6 $export, star(* 0.10 ** 0.05 *** 0.010) b(2) se(2) r2 ar2 label replace


***************************************
*** Figure 3: Effect of test participation on final exam performance 
***************************************

*** estimation
* treatment: 1-10 bonus points
forvalues i = 1/10 {
    global w = "bonus_`i'"
    
    eststo ipw_`i': teffects ipw (points_wo_bonus) ($w $vars), atet vce(robust)
    eststo psmatch_`i': teffects psmatch (points_wo_bonus) ($w $vars), atet vce(robust) nneighbor(3)
	eststo ipwra_`i': teffects ipwra (points_wo_bonus $vars) ($w $vars), atet vce(robust)
    
}

* results 
forvalues i = 1/10 {
esttab ipw_`i' psmatch_`i' ipwra_`i', keep(r1vs0.bonus_`i') star( + 0.20 * 0.10 ** 0.05 *** 0.010) b(3) se(3)
}


*** plotting
* IPW
coefplot ipw_1 ipw_2 ipw_3 ipw_4 ipw_5 ipw_6 ipw_7 ipw_8 ipw_9 ipw_10, ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f))	///
    coeflabels(r1vs0.bonus_1 = "Bonus {&ge} 1" r1vs0.bonus_2 = "Bonus {&ge} 2" r1vs0.bonus_3 = "Bonus {&ge} 3" r1vs0.bonus_4 = "Bonus {&ge} 4" r1vs0.bonus_5 = "Bonus {&ge} 5" r1vs0.bonus_6 = "Bonus {&ge} 6" r1vs0.bonus_7 = "Bonus {&ge} 7" r1vs0.bonus_8 = "Bonus {&ge} 8" r1vs0.bonus_9 = "Bonus {&ge} 9" r1vs0.bonus_10 = "Bonus {&ge} 10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("IPW") ///
    plotregion(margin(small)) ///
	fxsize(117.5) ///
    name(graph_ipw, replace)

* PSMATCH
coefplot psmatch_1 psmatch_2 psmatch_3 psmatch_4 psmatch_5 psmatch_6 psmatch_7 psmatch_8 psmatch_9 psmatch_10, ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f)) ///
    ylabel(, nolabel noticks) ///
    coeflabels(r1vs0.bonus_1 = "bonus_1" r1vs0.bonus_2 = "bonus_2" r1vs0.bonus_3 = "bonus_3" r1vs0.bonus_4 = "bonus_4" r1vs0.bonus_5 = "bonus_5" r1vs0.bonus_6 = "bonus_6" r1vs0.bonus_7 = "bonus_7" r1vs0.bonus_8 = "bonus_8" r1vs0.bonus_9 = "bonus_9" r1vs0.bonus_10 = "bonus_10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("PSMATCH") ///
    plotregion(margin(small)) ///
	fxsize(90) ///
    name(graph_psmatch, replace)

* IPWRA
coefplot ipwra_1 ipwra_2 ipwra_3 ipwra_4 ipwra_5 ipwra_6 ipwra_7 ipwra_8 ipwra_9 ipwra_10, ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f)) ///
    ylabel(, nolabel noticks) ///
    coeflabels(r1vs0.bonus_1 = "bonus_1" r1vs0.bonus_2 = "bonus_2" r1vs0.bonus_3 = "bonus_3" r1vs0.bonus_4 = "bonus_4" r1vs0.bonus_5 = "bonus_5" r1vs0.bonus_6 = "bonus_6" r1vs0.bonus_7 = "bonus_7" r1vs0.bonus_8 = "bonus_8" r1vs0.bonus_9 = "bonus_9" r1vs0.bonus_10 = "bonus_10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("IPWRA") ///
    plotregion(margin(small)) ///
	fxsize(90) ///
    name(graph_ipwra, replace)

* COMBINE
graph combine graph_ipw graph_psmatch graph_ipwra, ///
    col(3) ///
    ycommon xcommon ///
    imargin(0 2 0 0) ///
    iscale(0.9) ///
    xsize(8) ysize(4)
	
* export
*graph export "C:\Users\timba\OneDrive - Universität Bayreuth (1)\Uni\Research General\EVWL online test effectiveness assessment\Empirics\graphs\binary_treatment_results.pdf", as(pdf) name("Graph") replace

* export excluding extreme PS
* graph export "C:\Users\timba\OneDrive - Universität Bayreuth (1)\Uni\Research General\EVWL online test effectiveness assessment\Empirics\graphs\binary_treatment_results_ex.pdf", as(pdf) name("Graph") replace



***************************************
*** Figure 3: Placebo Testing online test participation and performance in macroeconomics I
***************************************

* estimations 
forvalues i = 1/6 {
    global w = "bonus_`i'"
    
	eststo psmatch_`i': teffects psmatch (macro) ($w $vars_excluding_Recht), atet vce(robust) nneighbor(3)

	eststo ipw_`i': teffects ipw (macro) ($w $vars), atet vce(robust)
    eststo ipwra_`i': teffects ipwra (macro $vars) ($w $vars), atet vce(robust)

}

* results 
forvalues i = 1/6 {
esttab ipw_`i' psmatch_`i' ipwra_`i', keep(r1vs0.bonus_`i') star( + 0.20 * 0.10 ** 0.05 *** 0.010) b(3) se(3)
}

*** plotting
* IPW
coefplot ipw_1 ipw_2 ipw_3 ipw_4 ipw_5 ipw_6 , ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f))	///
    coeflabels(r1vs0.bonus_1 = "Bonus {&ge} 1" r1vs0.bonus_2 = "Bonus {&ge} 2" r1vs0.bonus_3 = "Bonus {&ge} 3" r1vs0.bonus_4 = "Bonus {&ge} 4" r1vs0.bonus_5 = "Bonus {&ge} 5" r1vs0.bonus_6 = "Bonus {&ge} 6" r1vs0.bonus_7 = "Bonus {&ge} 7" r1vs0.bonus_8 = "Bonus {&ge} 8" r1vs0.bonus_9 = "Bonus {&ge} 9" r1vs0.bonus_10 = "Bonus {&ge} 10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("IPW") ///
    plotregion(margin(small)) ///
	fxsize(117.5) ///
    name(graph_ipw, replace)

* PSMATCH
coefplot psmatch_1 psmatch_2 psmatch_3 psmatch_4 psmatch_5 psmatch_6 , ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f)) ///
    ylabel(, nolabel noticks) ///
    coeflabels(r1vs0.bonus_1 = "bonus_1" r1vs0.bonus_2 = "bonus_2" r1vs0.bonus_3 = "bonus_3" r1vs0.bonus_4 = "bonus_4" r1vs0.bonus_5 = "bonus_5" r1vs0.bonus_6 = "bonus_6" r1vs0.bonus_7 = "bonus_7" r1vs0.bonus_8 = "bonus_8" r1vs0.bonus_9 = "bonus_9" r1vs0.bonus_10 = "bonus_10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("PSMATCH") ///
    plotregion(margin(small)) ///
	fxsize(90) ///
    name(graph_psmatch, replace)

* IPWRA
coefplot ipwra_1 ipwra_2 ipwra_3 ipwra_4 ipwra_5 ipwra_6 , ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f)) ///
    ylabel(, nolabel noticks) ///
    coeflabels(r1vs0.bonus_1 = "bonus_1" r1vs0.bonus_2 = "bonus_2" r1vs0.bonus_3 = "bonus_3" r1vs0.bonus_4 = "bonus_4" r1vs0.bonus_5 = "bonus_5" r1vs0.bonus_6 = "bonus_6" r1vs0.bonus_7 = "bonus_7" r1vs0.bonus_8 = "bonus_8" r1vs0.bonus_9 = "bonus_9" r1vs0.bonus_10 = "bonus_10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("IPWRA") ///
    plotregion(margin(small)) ///
	fxsize(90) ///
    name(graph_ipwra, replace)

* COMBINE
graph combine graph_ipw graph_psmatch graph_ipwra, ///
    col(3) ///
    ycommon xcommon ///
    imargin(0 2 0 0) ///
    iscale(0.9) ///
    xsize(8) ysize(4)
	
* export
* graph export "C:\Users\timba\OneDrive - Universität Bayreuth (1)\Uni\Research General\EVWL online test effectiveness assessment\Empirics\graphs\binary_treatment_placebo_treatment.pdf", as(pdf) name("Graph") replace

* export excluding extreme PS
* graph export "C:\Users\timba\OneDrive - Universität Bayreuth (1)\Uni\Research General\EVWL online test effectiveness assessment\Empirics\graphs\binary_treatment_placebo_treatment_ex.pdf", as(pdf) name("Graph") replace



***************************************
*** Figure 12: Reestimation of baseline model with subsample of macro students  
***************************************

forvalues i = 1/6 {
    global w = "bonus_`i'"
    
	eststo psmatch_`i': teffects psmatch (points_wo_bonus) ($w $vars_excluding_Recht), atet vce(robust) nneighbor(3)
	if `i' < 7 {
	global w = "bonus_`i'"
	eststo ipw_`i': teffects ipw (points_wo_bonus) ($w $vars), atet vce(robust)
    }
    eststo ipwra_`i': teffects ipwra (points_wo_bonus $vars) ($w $vars), atet vce(robust)	
}


*** plotting
* IPW
coefplot ipw_1 ipw_2 ipw_3 ipw_4 ipw_5 ipw_6, ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f))	///
    coeflabels(r1vs0.bonus_1 = "Bonus {&ge} 1" r1vs0.bonus_2 = "Bonus {&ge} 2" r1vs0.bonus_3 = "Bonus {&ge} 3" r1vs0.bonus_4 = "Bonus {&ge} 4" r1vs0.bonus_5 = "Bonus {&ge} 5" r1vs0.bonus_6 = "Bonus {&ge} 6" r1vs0.bonus_7 = "Bonus {&ge} 7" r1vs0.bonus_8 = "Bonus {&ge} 8" r1vs0.bonus_9 = "Bonus {&ge} 9" r1vs0.bonus_10 = "Bonus {&ge} 10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("IPW") ///
    plotregion(margin(small)) ///
	fxsize(117.5) ///
    name(graph_ipw, replace)

* PSMATCH
coefplot psmatch_1 psmatch_2 psmatch_3 psmatch_4 psmatch_5 psmatch_6 , ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xscale(range(-0.5 0.5)) ///
    xlabel(, format(%9.1f)) ///
    ylabel(, nolabel noticks) ///
    coeflabels(r1vs0.bonus_1 = "bonus_1" r1vs0.bonus_2 = "bonus_2" r1vs0.bonus_3 = "bonus_3" r1vs0.bonus_4 = "bonus_4" r1vs0.bonus_5 = "bonus_5" r1vs0.bonus_6 = "bonus_6" r1vs0.bonus_7 = "bonus_7" r1vs0.bonus_8 = "bonus_8" r1vs0.bonus_9 = "bonus_9" r1vs0.bonus_10 = "bonus_10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("PSMATCH") ///
    plotregion(margin(small)) ///
	fxsize(90) ///
    name(graph_psmatch, replace)
	
* IPWRA
coefplot ipwra_1 ipwra_2 ipwra_3 ipwra_4 ipwra_5 ipwra_6 , ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f)) ///
    ylabel(, nolabel noticks) ///
    coeflabels(r1vs0.bonus_1 = "bonus_1" r1vs0.bonus_2 = "bonus_2" r1vs0.bonus_3 = "bonus_3" r1vs0.bonus_4 = "bonus_4" r1vs0.bonus_5 = "bonus_5" r1vs0.bonus_6 = "bonus_6" r1vs0.bonus_7 = "bonus_7" r1vs0.bonus_8 = "bonus_8" r1vs0.bonus_9 = "bonus_9" r1vs0.bonus_10 = "bonus_10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("IPWRA") ///
    plotregion(margin(small)) ///
	fxsize(90) ///
    name(graph_ipwra, replace)

* COMBINE
graph combine graph_ipw graph_psmatch graph_ipwra, ///
    col(3) ///
    ycommon xcommon ///
    imargin(0 2 0 0) ///
    iscale(0.9) ///
    xsize(8) ysize(4)	

* export baseline for subsample of macro students 
* graph export "C:\Users\timba\OneDrive - Universität Bayreuth (1)\Uni\Research General\EVWL online test effectiveness assessment\Empirics\graphs\binary_treatment_placebo_treatment_baseline_comparison.pdf", as(pdf) name("Graph") replace



***************************************
*** Figure 6: Unintended side-effects
***************************************

*** estimation
* treatment: 1-10 bonus points
forvalues i = 1/10 {
    global w = "bonus_`i'"
    
    eststo ipw_`i': teffects ipw (average_grade_same_semester) ($w $vars), atet vce(robust)
    eststo psmatch_`i': teffects psmatch (average_grade_same_semester) ($w $vars), atet vce(robust) nneighbor(3)
	eststo ipwra_`i': teffects ipwra (average_grade_same_semester $vars) ($w $vars), atet vce(robust)
    
}

* results 
forvalues i = 1/10 {
esttab ipw_`i' psmatch_`i' ipwra_`i', keep(r1vs0.bonus_`i') star( + 0.20 * 0.10 ** 0.05 *** 0.010) b(3) se(3)
}

*** plotting
* IPW
coefplot ipw_1 ipw_2 ipw_3 ipw_4 ipw_5 ipw_6 ipw_7 ipw_8 ipw_9 ipw_10, ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f))	///
    coeflabels(r1vs0.bonus_1 = "Bonus {&ge} 1" r1vs0.bonus_2 = "Bonus {&ge} 2" r1vs0.bonus_3 = "Bonus {&ge} 3" r1vs0.bonus_4 = "Bonus {&ge} 4" r1vs0.bonus_5 = "Bonus {&ge} 5" r1vs0.bonus_6 = "Bonus {&ge} 6" r1vs0.bonus_7 = "Bonus {&ge} 7" r1vs0.bonus_8 = "Bonus {&ge} 8" r1vs0.bonus_9 = "Bonus {&ge} 9" r1vs0.bonus_10 = "Bonus {&ge} 10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("IPW") ///
    plotregion(margin(small)) ///
	fxsize(117.5) ///
    name(graph_ipw, replace)

* PSMATCH
coefplot psmatch_1 psmatch_2 psmatch_3 psmatch_4 psmatch_5 psmatch_6 psmatch_7 psmatch_8 psmatch_9 psmatch_10, ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f)) ///
    ylabel(, nolabel noticks) ///
    coeflabels(r1vs0.bonus_1 = "bonus_1" r1vs0.bonus_2 = "bonus_2" r1vs0.bonus_3 = "bonus_3" r1vs0.bonus_4 = "bonus_4" r1vs0.bonus_5 = "bonus_5" r1vs0.bonus_6 = "bonus_6" r1vs0.bonus_7 = "bonus_7" r1vs0.bonus_8 = "bonus_8" r1vs0.bonus_9 = "bonus_9" r1vs0.bonus_10 = "bonus_10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("PSMATCH") ///
    plotregion(margin(small)) ///
	fxsize(90) ///
    name(graph_psmatch, replace)

* IPWRA
coefplot ipwra_1 ipwra_2 ipwra_3 ipwra_4 ipwra_5 ipwra_6 ipwra_7 ipwra_8 ipwra_9 ipwra_10, ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f)) ///
    ylabel(, nolabel noticks) ///
    coeflabels(r1vs0.bonus_1 = "bonus_1" r1vs0.bonus_2 = "bonus_2" r1vs0.bonus_3 = "bonus_3" r1vs0.bonus_4 = "bonus_4" r1vs0.bonus_5 = "bonus_5" r1vs0.bonus_6 = "bonus_6" r1vs0.bonus_7 = "bonus_7" r1vs0.bonus_8 = "bonus_8" r1vs0.bonus_9 = "bonus_9" r1vs0.bonus_10 = "bonus_10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("IPWRA") ///
    plotregion(margin(small)) ///
	fxsize(90) ///
    name(graph_ipwra, replace)

* COMBINE
graph combine graph_ipw graph_psmatch graph_ipwra, ///
    col(3) ///
    ycommon xcommon ///
    imargin(0 2 0 0) ///
    iscale(0.9) ///
    xsize(8) ysize(4)

* export
* graph export "C:\Users\timba\OneDrive - Universität Bayreuth (1)\Uni\Research General\EVWL online test effectiveness assessment\Empirics\graphs\binary_treatment_side_effects.pdf", as(pdf) name("Graph") replace

* export excluding extreme PS
* graph export "C:\Users\timba\OneDrive - Universität Bayreuth (1)\Uni\Research General\EVWL online test effectiveness assessment\Empirics\graphs\binary_treatment_side_effects_ex.pdf", as(pdf) name("Graph") replace



***************************************
*** Figure 5: Placebo testing with average high school grade
***************************************

*** placebo testing with high school averages 
global vars = "average_grade_pre average_grade_quant_pre Antritt exam_semester ECTS_passed_pre ECTS_passed_quant_pre ECTS_econ_of_all_pre ECTS_same_semester Age female i.Exam_fe Sport_konomie Recht_Wirtschaft Rechtswissenschaft"

* estimations 
forvalues i = 1/10 {
    global w = "bonus_`i'"
    
	eststo psmatch_`i': teffects psmatch (high_school_average) ($w $vars), atet vce(robust) nneighbor(3)
	eststo ipw_`i': teffects ipw (high_school_average) ($w $vars), atet vce(robust)
    eststo ipwra_`i': teffects ipwra (high_school_average $vars) ($w $vars), atet vce(robust)	
}

* results 
forvalues i = 1/10 {
esttab ipw_`i' psmatch_`i' ipwra_`i', keep(r1vs0.bonus_`i') star( + 0.20 * 0.10 ** 0.05 *** 0.010) b(3) se(3)
}


*** plotting
* IPW
coefplot ipw_1 ipw_2 ipw_3 ipw_4 ipw_5 ipw_6 ipw_7 ipw_8 ipw_9 ipw_10, ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f))	///
    coeflabels(r1vs0.bonus_1 = "Bonus {&ge} 1" r1vs0.bonus_2 = "Bonus {&ge} 2" r1vs0.bonus_3 = "Bonus {&ge} 3" r1vs0.bonus_4 = "Bonus {&ge} 4" r1vs0.bonus_5 = "Bonus {&ge} 5" r1vs0.bonus_6 = "Bonus {&ge} 6" r1vs0.bonus_7 = "Bonus {&ge} 7" r1vs0.bonus_8 = "Bonus {&ge} 8" r1vs0.bonus_9 = "Bonus {&ge} 9" r1vs0.bonus_10 = "Bonus {&ge} 10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("IPW") ///
    plotregion(margin(small)) ///
	fxsize(117.5) ///
    name(graph_ipw, replace)

* PSMATCH
coefplot psmatch_1 psmatch_2 psmatch_3 psmatch_4 psmatch_5 psmatch_6 psmatch_7 psmatch_8 psmatch_9 psmatch_10, ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f)) ///
    ylabel(, nolabel noticks) ///
    coeflabels(r1vs0.bonus_1 = "bonus_1" r1vs0.bonus_2 = "bonus_2" r1vs0.bonus_3 = "bonus_3" r1vs0.bonus_4 = "bonus_4" r1vs0.bonus_5 = "bonus_5" r1vs0.bonus_6 = "bonus_6" r1vs0.bonus_7 = "bonus_7" r1vs0.bonus_8 = "bonus_8" r1vs0.bonus_9 = "bonus_9" r1vs0.bonus_10 = "bonus_10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("PSMATCH") ///
    plotregion(margin(small)) ///
	fxsize(90) ///
    name(graph_psmatch, replace)

* IPWRA
coefplot ipwra_1 ipwra_2 ipwra_3 ipwra_4 ipwra_5 ipwra_6 ipwra_7 ipwra_8 ipwra_9 ipwra_10, ///
	xline(0, lcolor(black) lpattern(dash)) ///
    xlabel(, format(%9.1f)) ///
    ylabel(, nolabel noticks) ///
    coeflabels(r1vs0.bonus_1 = "bonus_1" r1vs0.bonus_2 = "bonus_2" r1vs0.bonus_3 = "bonus_3" r1vs0.bonus_4 = "bonus_4" r1vs0.bonus_5 = "bonus_5" r1vs0.bonus_6 = "bonus_6" r1vs0.bonus_7 = "bonus_7" r1vs0.bonus_8 = "bonus_8" r1vs0.bonus_9 = "bonus_9" r1vs0.bonus_10 = "bonus_10")	///
    msymbol(D D D D D D D D D D) ///
    mcolor(black) ///
    ciopts(lcolor(black) lwidth(medium medium medium medium medium medium medium medium medium medium)) ///
    offset(0) ///
    legend(off) ///
    xtitle("Coefficient Estimate") ytitle("") ///
    title("IPWRA") ///
    plotregion(margin(small)) ///
	fxsize(90) ///
    name(graph_ipwra, replace)

* COMBINE
graph combine graph_ipw graph_psmatch graph_ipwra, ///
    col(3) ///
    ycommon xcommon ///
    imargin(0 2 0 0) ///
    iscale(0.9) ///
    xsize(8) ysize(4)

* export
* graph export "C:\Users\timba\OneDrive - Universität Bayreuth (1)\Uni\Research General\EVWL online test effectiveness assessment\Empirics\graphs\binary_treatment_placebo_high_school_average.pdf", as(pdf) name("Graph") replace






